package SmartQuestions;

import questionsObjects.Questions;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;

/**
 * Created with IntelliJ IDEA.
 * User: xpk
 * Date: 11/30/13
 * Time: 3:03 PM
 * To change this template use File | Settings | File Templates.
 */
class ComplexityOfQuestion {
    private List<Integer> allComplexities;
    private ListIterator<Integer> allComplexitiesIterator;
    private final Questions questions;

    public ComplexityOfQuestion(String currentTheme, Questions questions) {
        this.questions = questions;
        this.allComplexities = new ArrayList<Integer>();

        for (int i = 0; i < this.questions.length(); i++) {
            if (this.questions.getTheme(i).equals(currentTheme)) {
                if (!this.allComplexities.contains(this.questions.getComplexity(i))) {
                    this.allComplexities.add(this.questions.getComplexity(i));
                }
            }
        }

        Collections.sort(allComplexities);
        this.allComplexitiesIterator = this.allComplexities.listIterator();
    }

    public int growingDownComplexity() {
        allComplexitiesIterator.previous();
        return allComplexitiesIterator.hasPrevious() ? allComplexitiesIterator.previous() : -1;
    }

    public int growingUpComplexity() {
        return allComplexitiesIterator.hasNext() ? allComplexitiesIterator.next() : -1;
    }
}
